<style>
    #authTable + .layui-table-view .layui-table tbody tr:hover {
        background-color: transparent;
    }
</style>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-form lay-header">
                <div class="toolbar">
                    <div class="layui-form-item lay-query-content">
                        <div class="lay-query-box">
                            <div class="query-lt">
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">关键字：</label>
                                    <div class="layui-input-inline">
                                        <input name="keyword" class="layui-input" type="text" placeholder="请输入关键字"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <button class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog" lay-submit layui-form-keyDownSearch="true">查询</button>
                                    <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit>重置</button>
                                </div>
                            </div>
                            <div class="query-rt"></div>
                        </div>
                    </div>
                </div>
                <div class="lay-btn-rows">
                    <div class="lay-btn-box">
                        <div class="lay-btn-lt">
                            <button id="authBtnSync" class="layui-btn icon-btn color-reseda">同步</button>
                        </div>
                        <div class="lay-btn-rt">

                        </div>
                    </div>
                </div>
            </div>
            <!-- 数据表格 -->
            <table class="layui-table" id="authTable" lay-filter="authTable"></table>
        </div>
    </div>
</div>

<script>
    layui.use(['jquery', 'form', 'table', 'util', 'admin', 'config', 'tableX'], function () {
        var $ = layui.jquery;
        var table = layui.table;
        var layer = layui.layer;
        var admin = layui.admin;
        var config = layui.config;
        var tableX = layui.tableX;
        var form = layui.form;

        // 渲染表格
        var insTb = table.render({
            elem: '#authTable',
            url: config.base + 'user/admin/authority/list',
            page: true,
            cellMinWidth: 100,
            cols: [[
                {type: 'numbers',title: '序号'},
                {field: 'pageUrl', sort: true, title: '页面URL'},
                {field: 'buttonName', sort: true, title: '按钮名称'},
                {field: 'authorityName', sort: true, title: '接口名称'},
                {field: 'authority', sort: true, title: '权限标识'},
                {field: 'createTime', sort: true, title: '同步时间', width: 165}
            ]],
            done: function (res, curr, count) {
                tableX.merges('authTable', [1], ['pageUrl']);
                //移除按钮
                var menuButton = config.getMenuButton(location.hash);
                if(menuButton.indexOf("搜索") == -1){
                    $('.search').remove();
                }
                if(menuButton.indexOf("同步") == -1){
                    $("#authBtnSync").remove();
                }
            }
        });

        // 搜索
        form.on('submit(formSubSearchLog)', function (data) {
            insTb.reload({where: data.field,page: {curr: 1}},'data');
        });

        // 重置搜索
        form.on('submit(resets)', function (data) {
            insTb.reload({where: admin.resetSearch(data.field), page: {curr: 1}}, 'data');
        });

        // 同步按钮点击事件
        $('#authBtnSync').click(function () {
            layer.confirm('确定进行同步吗？<br><span style="color: red;">（自动扫描所有接口生成权限标识）</span>', {
                skin: 'layui-layer-admin'
            }, function () {
                layer.load(2);
                // 保存
                admin.req('user/admin/authority/sync', {}, function (res) {
                    layer.closeAll('loading');
                    if (200 == res.code) {
                        layer.msg(res.msg, {icon: 1});
                        table.reload('authTable');
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }, 'POST');
            });
        });

    });
</script>